/**
 * 移除注释
 */
const pluginName = 'RemoveCommentPlugin'
class RemoveCommentPlugin {
	apply(compiler) {
		compiler.hooks.emit.tap(pluginName, (compilation) => {
			for (const name in compilation.assets) {
				if (name.endsWith('.js')) {
					let contents = compilation.assets[name].source()
					const noComments = contents.replace(/\/\*{2,}\/s?/g, '')
					compilation.assets[name] = {
						source: () => noComments,
						size: () => noComments.length
					}
				}
			}
		})
	}
}
module.exports = RemoveCommentPlugin
